using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SiRtEt
{
    /// <summary>
    /// Summary description for SiRtEt. The SiRtEt class is the main window for the game and contains the menu
    /// and other controls specific to the game. The user needs to go through this class to start a game.
    /// </summary>
    public class sirtet : System.Windows.Forms.Form
    {
        private IContainer components;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem menuItem2;
        private System.Windows.Forms.MenuItem menuItem3;
        private GamePanel TheGamePanels;
        private MenuItem menuAbout;
        private MenuItem mnuControls;
        private System.Windows.Forms.MenuItem menuHelp;

        /// <summary>
        /// Constructor: Creates an instance of the system
        /// </summary>
        public sirtet()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
        }

        #region Disposer
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        #endregion

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuHelp = new System.Windows.Forms.MenuItem();
            this.menuAbout = new System.Windows.Forms.MenuItem();
            this.TheGamePanels = new SiRtEt.GamePanel();
            this.mnuControls = new System.Windows.Forms.MenuItem();
            this.SuspendLayout();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuHelp});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem2,
            this.menuItem3});
            this.menuItem1.Text = "&Game";
            // 
            // menuItem2
            // 
            this.menuItem2.Index = 0;
            this.menuItem2.Text = "&New Game";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 1;
            this.menuItem3.Text = "E&xit";
            this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
            // 
            // menuHelp
            // 
            this.menuHelp.Index = 1;
            this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuAbout,
            this.mnuControls});
            this.menuHelp.Text = "&Help";
            // 
            // menuAbout
            // 
            this.menuAbout.Index = 0;
            this.menuAbout.Text = "&About";
            this.menuAbout.Click += new System.EventHandler(this.menuAbout_Click);
            // 
            // TheGamePanels
            // 
            this.TheGamePanels.BackColor = System.Drawing.Color.Black;
            this.TheGamePanels.Location = new System.Drawing.Point(0, 0);
            this.TheGamePanels.Name = "TheGamePanels";
            this.TheGamePanels.Size = new System.Drawing.Size(336, 406);
            this.TheGamePanels.TabIndex = 0;
            // 
            // mnuControls
            // 
            this.mnuControls.Index = 1;
            this.mnuControls.Text = "Controls";
            this.mnuControls.Click += new System.EventHandler(this.mnuControls_Click);
            // 
            // sirtet
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(336, 406);
            this.Controls.Add(this.TheGamePanels);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Menu = this.mainMenu1;
            this.Name = "sirtet";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "SiRtEt";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// Main Entry point for the system
        /// </summary>
        static void Main()
        {
            Application.Run(new sirtet());
        }

        #region Menu Items
        /// <summary>
        /// Starts a new game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem2_Click(object sender, System.EventArgs e)
        {
            if (TheGamePanels.TheGame.GameStart)
            {
                TheGamePanels.TheGame.GamePause();
                DialogResult userResponse =
                MessageBox.Show("Are you sure you want to start a new game?", "SiRtEt",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                    MessageBoxOptions.DefaultDesktopOnly, false);

                if (userResponse.Equals(DialogResult.No))
                {
                    TheGamePanels.TheGame.GamePause();
                    TheGamePanels.Focus();
                    return;
                }

                TheGamePanels.TheGame.ToDoAtGameEnd();
            }
            TheGamePanels.TheGame.InitializeNewGame();
        }

        /// <summary>
        /// Cleans up the resources
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem3_Click(object sender, System.EventArgs e)
        {

            DialogResult userResponse =
            MessageBox.Show("Are you sure you want to Quit?", "SiRtEt", MessageBoxButtons.YesNo,
                MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly,
                false);

            if (TheGamePanels.TheGame.GameStart)
            {
                TheGamePanels.TheGame.GamePause();
            }

            if (userResponse.Equals(DialogResult.No))
            {
                if (TheGamePanels.TheGame.GameStart)
                    TheGamePanels.TheGame.GamePause();

                this.Focus();
                TheGamePanels.Focus();
                return;
            }

            this.Dispose();
            Application.Exit();
        }

        /// <summary>
        /// The about window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuAbout_Click(object sender, System.EventArgs e)
        {
            if (TheGamePanels.TheGame.GameStart)
            {
                TheGamePanels.TheGame.GamePause();
            }

            AboutForm about = new AboutForm();
            about.TopMost = true;
            about.Show(this);
        }


        #endregion

        private void mnuControls_Click(object sender, EventArgs e)
        {
            (new Controls()).Show(this);
        }

    }
}
